package com.mf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mf.Enum.EnumRelevanceStatus;
import com.mf.entity.dto.DtoIncoming;
import com.mf.entity.req.search.SearchReqIncoming;
import com.mf.mapper.MapperIncoming;
import com.mf.service.ServiceIncoming;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
public class ImplServiceIncoming extends ServiceImpl<MapperIncoming, DtoIncoming> implements ServiceIncoming {


    /**
     * 参数查询条件
     */
    @Override
    public LambdaQueryWrapper<DtoIncoming> fillParams(SearchReqIncoming params) {
        LambdaQueryWrapper<DtoIncoming> wrapper = loadQw();
        wrapper.eq(ObjectUtils.isNotEmpty(params.getCustomerId()), DtoIncoming::getCustomerId, params.getCustomerId())
                .like(StringUtils.isNotEmpty(params.getCarNum()), DtoIncoming::getCarNum, params.getCarNum())
                .between(ObjectUtils.isNotEmpty(params.getStart()) && ObjectUtils.isNotEmpty(params.getEnd()),
                        DtoIncoming::getArrivalDate,
                        params.getStart(),
                        params.getEnd());

        return wrapper;
    }


    /**
     * 修改来料单关联状态
     */
    @Override
    @Transactional
    public void updateRelevancyStatus(Integer incomingId, Integer status) {
        // 更新来料单关联状态
        DtoIncoming dtoIncoming = new DtoIncoming();
        dtoIncoming.setRelevanceStatus(status);
        dtoIncoming.setId(incomingId);
        this.updateById(dtoIncoming);
    }
}